﻿using System;
using System.Collections.Generic;   
using System.Linq;
using System.Text;
using System.Data;
using XMK.Framework.Model;
using XMK.Tadong.Data;
using XMK.Tadong.Model;  
using XMK.Utils;
using XMK.Tadong.Model.Cond;
using XMK.Utils;

namespace XMK.Tadong.Biz
{   
   public class Tb_Team_UserBiz
    {
       public Tb_Team_UserBiz()
       { 
       }
       /// <summary>
       /// 获得课题组对象
       /// </summary>
       /// <param name="teamID"></param>
       /// <returns></returns>
       public DataTable GetTeamListByUserId(string userId)
       {
           TB_TEAM_USER_userData data = new TB_TEAM_USER_userData(Config.TadongDbProvider);
           return data.GetTeamListByUserId(userId);
       }
       /// <summary>
       /// 添加
       /// </summary>
       /// <param name="teamObj"></param>
       /// <returns></returns>
       public bool addTeam(TB_TEAMInfo teamObj)
       {
           Tb_TeamData data = new Tb_TeamData(Config.TadongDbProvider);
           return data.InsertNewTeam(teamObj);
       }
       public List<Base_UserSpaceInfo> GetSpaceListByUserId(string userId)
       {
           List<Base_UserSpaceInfo> spaces = new List<Base_UserSpaceInfo>();
           TB_TEAM_USER_userData teamUserData = new TB_TEAM_USER_userData(Config.TadongDbProvider);
            DataTable dt =  teamUserData.GetTeamDetailListByUserId(userId);

            foreach (DataRow row in dt.Rows)
            {
                Base_UserSpaceInfo info = new Base_UserSpaceInfo();
                info.SpaceName = ParseHelper.Parse<string>(row["TEAM_NAME"]);
                //info.SpaceId = ParseHelper.Parse<string>(row["TEAM_ID"]);
                info.IsAdmin = ParseHelper.Parse<string>(row["TEAM_LEADER"])== userId;
                info.SpaceId = ParseHelper.Parse<decimal>(row["TEAM_ID"]).ToString();
                info.IsOpen = ParseHelper.Parse<decimal>(row["TEAM_STS"]) > 0;
                info.IsDataAdmin = ParseHelper.Parse<decimal>(row["DATAADMIN"]) == 1;
                spaces.Add(info);
            }


           return spaces;
       }
       /// <summary>
       /// 判断当前用户是否是项目库管理员
       /// </summary>
       /// <param name="teamObj"></param>
       /// <returns></returns>
       public ResponseInfo isXmkAdmin()
       {
           ResponseInfo response = null;
           string userId = LoginUserBiz.LoginUserID();
           try
           {
               Tb_TeamData data = new Tb_TeamData(Config.TadongDbProvider);
               response = new ResponseInfo();
               response.Data = (bool)data.isXmkAdmin(userId);
           }
           catch (Exception ex)
           {
               //生成返回对象（带错误信息）
               response = new ResponseInfo("error！");
               LogHelper.WriteLog(LogType.Error, "[QueryDictTableRoleSave:]" + ex.ToString());
           }
           return response;
           
       }
    }
}
